package com.neu.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel("响应结果")
public class Result<T> {
    /**
     * 返回码 1:成功 0:失败
     */
    @ApiModelProperty(value = "返回码 1:成功 0:失败")
    private int code;
    @ApiModelProperty(value = "返回信息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private T data;



    public static<E> Result<E> success(E data) {
        return new Result(1, "操作成功", data);
    }
    //快速返回操作成功响应结果
    public static Result success() {
        return new Result(1, "操作成功", null);
    }

    public static Result error(String message) {
        return new Result(0, message, null);
    }
    public static Result<?> error(int code, String message) {
        return new Result<>(code, message, null);
    }
}
